package org.study.daka.pksms;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.study.daka.pksms.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class SMSContentAdapter extends RecyclerView.Adapter<SMSContentAdapter.SMSViewHolder> {

    private List<MainActivity.SMS> list;
    private Context context;
    private View view;

    public SMSContentAdapter(Context context, List<MainActivity.SMS> list) {
        if (list == null) {
            list = new ArrayList<>();
        }
        this.list = list;
        this.context = context;
    }


    @NonNull
    @Override
    public SMSViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.rc_sms_item, parent,false);
        SMSViewHolder holder = new SMSViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull SMSViewHolder holder, int position) {
        MainActivity.SMS sms = list.get(position);
        holder.tv.setText(sms.getContent());
        holder.num.setText(sms.getNum());
        holder.tvid.setText(sms.getId());
        holder.tvdate.setText(sms.getDate());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class SMSViewHolder extends RecyclerView.ViewHolder {

        CheckBox cb;
        TextView tv;
        TextView num;
        TextView tvid;

        TextView tvdate;

        public SMSViewHolder(@NonNull View itemView) {
            super(itemView);
            cb = itemView.findViewById(R.id.cb_rc_sms_item_id);
            tv = itemView.findViewById(R.id.tv_rc_sms_item_content);
            num = itemView.findViewById(R.id.tv_rc_sms_item_num);
            tvid = itemView.findViewById(R.id.tv_rc_sms_item_id);
            tvdate = itemView.findViewById(R.id.tv_Rc_sms_item_date);
        }
    }
}
